#include "StdAfx.h"
#include "CodeViewManager.h"


CCodeViewManager::CCodeViewManager(const CStringA &a_strCode) :
m_strCode(a_strCode),
m_pView(NULL)
{
}


VOID CCodeViewManager::NotifyViewClosed()
{
	m_pView = NULL;
}


BOOL CCodeViewManager::IsViewOpen() const
{
	return m_pView != NULL;
}

VOID CCodeViewManager::OpenView()
{
	if (m_pView != NULL)
	{
		m_pView->MDIActivate();
		return;
	}

	m_pView = new CCodeView(*this);
	if (m_pView == NULL)
	{
		TRACE(_T("Warning: failed to create MDI child view\n"));
		return;
	}

	m_pView->Create(m_strCode);
}

VOID CCodeViewManager::CloseView()
{
	if (m_pView != NULL)
	{
		m_pView->MDIDestroy();
		m_pView = NULL;
	}
}

VOID CCodeViewManager::ToggleView()
{
	if (m_pView != NULL)
	{
		CloseView();
	}
	else
	{
		OpenView();
	}
}
